package com.scqzy.shengchunqiang.sword2offer.day11;

import com.scqzy.shengchunqiang.structure.ListNode;

import java.util.Objects;

/**
 * @Description: 剑指 Offer 18. 删除链表的节点
 * @Author 盛春强
 * @Date 2021/8/18 15:09
 */
public class DeleteNode {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode tail = new ListNode(-1);
        tail.next = head;
        ListNode node = tail;
        while (Objects.nonNull(node.next)) {
            if (node.next.val == val) {
                node.next = node.next.next;
                break;
            }
            node = node.next;
        }
        return tail.next;
    }
}
